// 独立封装的axios请求模块
import request from '@/utils/request.js';

import store from '@/store';
// 获取登录数据的接口
export const login = (data) => {
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  });
};

// 获取验证码数据的接口
export const sendSms = (mobile) => {
  return requestAnimationFrame({
    method: 'GET',
    url: `/v1_0/sms/codes/${mobile}`
  });
};

export const getUserInfo = () => {
  console.log(store.state.user);
  return request({
    method: 'GET',
    url: '/v1_0/user',
    headers: {
      Authorization: `Bearer ${store.state.user.token}`
    }
  })
};

export const getUserChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/channels'
  })
}

// 添加关注 target为作者id
export const addFollow = target => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

// 取消关注 target为作者id
export const deleteFollow = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${target}`
  })
}

// 获取用户资料
export const getUserProfile = target => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

// 更新用户信息
export const updateUserProfile = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}
